import { current } from '@reduxjs/toolkit';
import React,{useEffect} from 'react';


import Search from '../components/users/Search';
import Table from '../components/users/Table';
import { getAll } from '../services/user';
export default () => {
    //查看地址
    let [addr,setAddr]=React.useState([]);
    //渲染页面
    let [users,setUsers]=React.useState([]);
    let [searchObj,setSearchObj] = React.useState({});
    let [pagination, setPagination] = React.useState({
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: (total) => `总共 ${total} 条`,
        pageSizeOptions: [5, 10, 15, 20],
    });
    const show=async(params)=>{
        if (params) {
            if (!params.current) {
                params.current = 1;
                params.pageSize = pagination.pageSize;
            }
            params = { ...searchObj, ...params };
            setSearchObj(params);
            
        } else {
            params = searchObj;
        }
        // console.log("params:",params);
        let data=await getAll(params);
        console.log(data);
        setUsers(data.data.rows);
        setPagination({
            ...pagination,
            total: data.data.total,
            current: parseInt(data.data.current),
            pageSize: data.data.pageSize,
        });
    }
    useEffect(()=>{
        show()
    },[users.length]);


    ;
    return (
        <div>

            <Search show={show}></Search>
            <Table setAddr={setAddr} addr={addr} show={show} users={users} pagination={pagination}></Table>
        </div>
    )
}
